package suite;

import java.util.ArrayList;

import suite.exception.SuiteInvalidaException;
import util.ErroAcessoRepositorioException;
import junit.framework.TestCase;

public class SuiteTest extends TestCase {

	SuiteAbstrata s1;
	SuiteAbstrata s2;
	SuiteAbstrata s3;
	SuiteAbstrata s4;
	SuiteAbstrata s5;
	SuiteAbstrata s6;
	SuiteAbstrata s7;
	SuiteAbstrata s8;
	
	RepositorioSuitesBDR rep = new RepositorioSuitesBDR();
	
	protected void setUp() throws Exception {
		s1 = new SuiteStandard(0,"teste alterar",3,123,12.3);
		s2 = new SuiteStandard(1,"111",1,1.3,1.3);
		s3 = new SuiteLuxo(2,"testa",2,666,6666);
		s4 = new SuiteLuxo(3,"333",2,44,44);
		s5 = new SuiteSuperLuxo(4,"444",3,55,5);
		s6 = new SuiteSuperLuxo(5,"555",1,666,6);
		s7 = new SuitePresidencial(6,"666",3,777,77);
		s8 = new SuitePresidencial(7,"777",1,7,777);
		
	}

	public void testAtualizarSuite() {
		try {
			//rep.atualizarSuite(s1);
			rep.atualizarSuite(s3);
		} catch (SuiteInvalidaException e) {
			fail("suite invalida");
		} catch (ErroAcessoRepositorioException e) {
			fail("erro no acesso ao repositorio");
		}
		
	}

	public void testConsultarSuite() {
		try {
			SuiteAbstrata s = rep.consultarSuite(0);
			System.out.println(s.getNumeroSuite()+"--");
			System.out.println(s.getRamal()+"--");
			System.out.println(s.getStatusSuite()+"--");
			System.out.println(s.getPrecoHoraExcedente()+"--");
			System.out.println(s.getPreco()+"--");
			if (s instanceof SuiteStandard)
				System.out.println(1+"--");
			if (s instanceof SuiteLuxo)
				System.out.println(2+"--");
			if (s instanceof SuiteSuperLuxo)
				System.out.println(3+"--");
			if (s instanceof SuitePresidencial)
				System.out.println(4+"--");
		} catch (SuiteInvalidaException e) {
			fail("suite invalida");
		} catch (ErroAcessoRepositorioException e) {
			fail("erro no acesso ao repositorio");
		}
	}

	public void testExcluirSuite() {
		try {
			rep.excluirSuite(4);
		} catch (SuiteInvalidaException e) {
			fail("suite invalida");
		} catch (ErroAcessoRepositorioException e) {
			fail("erro no acesso ao repositorio");
		}
	}

	public void testInserirSuite() {
		
		try {
			rep.inserirSuite(s2);
			rep.inserirSuite(s4);
			rep.inserirSuite(s6);
			rep.inserirSuite(s8);
		} catch (ErroAcessoRepositorioException e) {
			fail("erro no acesso ao repositorio");
		}
		
	}

	public void testListarSuites() {
		try {
			ArrayList<SuiteAbstrata> suites = (ArrayList<SuiteAbstrata>)rep.listarSuites();
			for(SuiteAbstrata s : suites){
				System.out.println("**************");
				System.out.println(s.getNumeroSuite()+"--");
				System.out.println(s.getRamal()+"--");
				System.out.println(s.getStatusSuite()+"--");
				System.out.println(s.getPrecoHoraExcedente()+"--");
				System.out.println(s.getPreco()+"--");
				if (s instanceof SuiteStandard)
					System.out.println(1+"--");
				if (s instanceof SuiteLuxo)
					System.out.println(2+"--");
				if (s instanceof SuiteSuperLuxo)
					System.out.println(3+"--");
				if (s instanceof SuitePresidencial)
					System.out.println(4+"--");
				System.out.println("**************");
			}
		} catch (ErroAcessoRepositorioException e) {
			fail("erro no acesso ao repositorio");
		}
	}

}
